/**
 * Created by bean on 12/3/16.
 */
var http = require('http').Server();
var Redis = require('ioredis');
var io = require('socket.io')(http);
var redis = new Redis;
var setRedis = new Redis;
redis.subscribe('test-channel');

redis.on('message',function (channel,message) {
   console.log(message);
   message = JSON.parse(message);
   io.emit(channel,message.data);
});
//监听用户连接
io.on('connection',function (socket) {
   console.log(socket);
   console.log('a new user connected');
   io.emit('test-channel','A new user connect');
   //监听用户信息
   socket.on('messages',function (data) {
      console.log(data);
      io.emit('test-channel',data);
   });
});

http.listen(3000);